// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: jing

#pragma once
#include <experimental/filesystem>
#include <map>
#include <optional>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include <boost/bimap.hpp>
#include <toml.hpp>

#include "coin/proto/coin_market_enums.pb.h"
#include "coin2/exchange/base/market/market_exchange_api.h"

namespace impl {

using namespace coin::proto;
using coin2::exchange::base::market::MarketExchangeApi;

using CurrencyMap = boost::bimap<std::string, std::string>;
using CurrencyPair = CurrencyMap::value_type;

// This represents the specification of exchange.
// This is different from our configuration.
struct SymbologySpec {
  std::string feed_symbol;
  std::string order_symbol;
  bool native_currency_lower_case;
  CurrencyMap currencies;
};

class SymbologySpecMap {
 public:
  explicit SymbologySpecMap(const std::experimental::filesystem::path& filename);

  const SymbologySpec& at(const MarketExchangeApi& mea) const {
    CHECK_EQ_THROW(map_.count(mea), 1) << "Cannot find symbology spec for " << mea.String();
    return map_.at(mea);
  }

 private:
  std::unordered_map<MarketExchangeApi, SymbologySpec> map_;
};

}  // namespace impl

using impl::SymbologySpec;
using impl::SymbologySpecMap;
